/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.remiseria.frame;

import ar.com.remiseria.bo.AutoBO;
import ar.com.remiseria.bo.ChoferBO;
import ar.com.remiseria.bo.ClienteBO;
import ar.com.remiseria.bo.DestinoFrecuenteBO;
import ar.com.remiseria.bo.TipoDeDocumentoBO;
import ar.com.remiseria.bo.ViajeBO;
import ar.com.remiseria.entities.Auto;
import ar.com.remiseria.entities.Chofer;
import ar.com.remiseria.entities.Cliente;
import ar.com.remiseria.entities.DestinoFrecuente;
import ar.com.remiseria.entities.Documento;
import ar.com.remiseria.entities.Domicilio;
import ar.com.remiseria.entities.TipoDeDocumento;
import ar.com.remiseria.utils.PropertiesReader;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author mcvalls
 */
public class AltaPedidoFrame extends javax.swing.JFrame {

    /*
     Defino atributos locales a la clase
     */
    private Cliente clienteActual;
    private List<Chofer> listaChoferes = new ArrayList<Chofer>();
    private List<Auto> listaAutos = new ArrayList<Auto>();
    private List<TipoDeDocumento> tiposDocumentoList = new ArrayList<TipoDeDocumento>();
    private List<DestinoFrecuente> destinosFrecuentesList = new ArrayList<DestinoFrecuente>();

    /**
     * Creates new form AltaPedidoFrame
     */
    public AltaPedidoFrame() {
        initComponents();
        telefonoTxt.setFocusable(true);
        this.getTiposDocumento();
        this.getChoferes();
        this.getAutomoviles();
        this.getDomiciliosPrecargados();
        guardarClienteBtn.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        origenPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        telefonoTxt = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        nombreClienteTxt = new javax.swing.JTextField();
        apellidoClienteTxt = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        calleClienteTxt = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        numeroDocumentoClienteTxt = new javax.swing.JTextField();
        numeroClienteTxt = new javax.swing.JTextField();
        pisoClienteTxt = new javax.swing.JTextField();
        departamentoClienteTxt = new javax.swing.JTextField();
        codigoPostalClienteTxt = new javax.swing.JTextField();
        localidadClienteTxt = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        provinciaClienteTxt = new javax.swing.JTextField();
        informacionLbl = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        tipoDocumentoComboBox = new javax.swing.JComboBox();
        fechaRecogidaChooser = new com.toedter.calendar.JDateChooser();
        horarioRecogidaTxt = new javax.swing.JFormattedTextField();
        origenComboBox = new javax.swing.JComboBox();
        jLabel27 = new javax.swing.JLabel();
        guardarClienteBtn = new javax.swing.JButton();
        jLabel28 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        calleDestinoTxt = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        numeroDestinoTxt = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        pisoDestinoTxt = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        departamentoDestinoTxt = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        codigoPostalDestinoTxt = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        localidadDestinoTxt = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        provinciaDestinoTxt = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        observacionesDestinoTxt = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        destinoComboBox = new javax.swing.JComboBox();
        guardarViajeBtn = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        choferComboBox = new javax.swing.JComboBox();
        jLabel22 = new javax.swing.JLabel();
        documentoChoferTxt = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        automovilesComboBox = new javax.swing.JComboBox();
        jLabel24 = new javax.swing.JLabel();
        dominioAutomovilTxt = new javax.swing.JTextField();
        volverBtn = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        archivoMenuBtn = new javax.swing.JMenu();
        guardarViajeMenuBtn = new javax.swing.JMenuItem();
        volverMenuBtn = new javax.swing.JMenuItem();
        ayudaMenuBtn = new javax.swing.JMenu();
        ayudaAltaPedidoMenuBtn = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        origenPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Datos de Origen"));

        jLabel1.setText("Telefono:");

        telefonoTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                telefonoTxtFocusLost(evt);
            }
        });
        telefonoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                telefonoTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                telefonoTxtKeyPressed(evt);
            }
        });

        jLabel2.setText("Nombre");

        jLabel3.setText("Apellido");

        nombreClienteTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                nombreClienteTxtFocusLost(evt);
            }
        });
        nombreClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                nombreClienteTxtKeyPressed(evt);
            }
        });

        apellidoClienteTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                apellidoClienteTxtFocusLost(evt);
            }
        });
        apellidoClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                apellidoClienteTxtKeyPressed(evt);
            }
        });

        jLabel4.setText("Calle");

        calleClienteTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                calleClienteTxtFocusLost(evt);
            }
        });
        calleClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                calleClienteTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                calleClienteTxtKeyPressed(evt);
            }
        });

        jLabel5.setText("Numero Documento");

        numeroDocumentoClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                numeroDocumentoClienteTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                numeroDocumentoClienteTxtKeyPressed(evt);
            }
        });

        numeroClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                numeroClienteTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                numeroClienteTxtKeyPressed(evt);
            }
        });

        pisoClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                pisoClienteTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                pisoClienteTxtKeyPressed(evt);
            }
        });

        departamentoClienteTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                departamentoClienteTxtFocusLost(evt);
            }
        });
        departamentoClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                departamentoClienteTxtKeyPressed(evt);
            }
        });

        codigoPostalClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                codigoPostalClienteTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                codigoPostalClienteTxtKeyPressed(evt);
            }
        });

        localidadClienteTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                localidadClienteTxtFocusLost(evt);
            }
        });
        localidadClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                localidadClienteTxtKeyPressed(evt);
            }
        });

        jLabel6.setText("Numero");

        jLabel7.setText("Piso");

        jLabel8.setText("Departamento");

        jLabel9.setText("C.P.");

        jLabel10.setText("Localidad");

        jLabel11.setText("Provincia");

        provinciaClienteTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                provinciaClienteTxtFocusLost(evt);
            }
        });
        provinciaClienteTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                provinciaClienteTxtKeyPressed(evt);
            }
        });

        jLabel20.setText("Fecha y horario de recogida:");

        jLabel25.setText("Tipo documento");

        horarioRecogidaTxt.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));

        origenComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                origenComboBoxItemStateChanged(evt);
            }
        });
        origenComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                origenComboBoxActionPerformed(evt);
            }
        });

        jLabel27.setText("Domicilios precargados:");

        guardarClienteBtn.setText("Guardar cliente");
        guardarClienteBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarClienteBtnActionPerformed(evt);
            }
        });

        jLabel28.setText("hh:mm");

        javax.swing.GroupLayout origenPanelLayout = new javax.swing.GroupLayout(origenPanel);
        origenPanel.setLayout(origenPanelLayout);
        origenPanelLayout.setHorizontalGroup(
            origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(origenPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(origenPanelLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nombreClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(apellidoClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel25)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(tipoDocumentoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(numeroDocumentoClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(origenPanelLayout.createSequentialGroup()
                        .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(origenPanelLayout.createSequentialGroup()
                                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, origenPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(telefonoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(informacionLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, origenPanelLayout.createSequentialGroup()
                                        .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel4)
                                            .addComponent(jLabel9))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(origenPanelLayout.createSequentialGroup()
                                                .addComponent(calleClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel6)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(numeroClienteTxt))
                                            .addGroup(origenPanelLayout.createSequentialGroup()
                                                .addComponent(codigoPostalClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(31, 31, 31)
                                                .addComponent(jLabel10)
                                                .addGap(9, 9, 9)
                                                .addComponent(localidadClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel11))
                                .addGap(10, 10, 10)
                                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(origenPanelLayout.createSequentialGroup()
                                        .addComponent(pisoClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(4, 4, 4)
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(departamentoClienteTxt))
                                    .addComponent(provinciaClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(origenPanelLayout.createSequentialGroup()
                                .addComponent(jLabel27)
                                .addGap(3, 3, 3)
                                .addComponent(origenComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(0, 46, Short.MAX_VALUE))
                    .addGroup(origenPanelLayout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fechaRecogidaChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(horarioRecogidaTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel28)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(guardarClienteBtn)))
                .addContainerGap())
        );
        origenPanelLayout.setVerticalGroup(
            origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(origenPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(telefonoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(informacionLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(origenComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel27))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(calleClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(numeroClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(departamentoClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pisoClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(codigoPostalClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(localidadClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(provinciaClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(nombreClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(apellidoClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5)
                    .addComponent(numeroDocumentoClienteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel25)
                    .addComponent(tipoDocumentoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel20)
                    .addComponent(fechaRecogidaChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(origenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(horarioRecogidaTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(guardarClienteBtn)
                        .addComponent(jLabel28)))
                .addGap(15, 15, 15))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Datos de Destino"));

        jLabel12.setText("Calle");

        calleDestinoTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                calleDestinoTxtFocusLost(evt);
            }
        });
        calleDestinoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                calleDestinoTxtKeyPressed(evt);
            }
        });

        jLabel13.setText("Numero");

        numeroDestinoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                numeroDestinoTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                numeroDestinoTxtKeyPressed(evt);
            }
        });

        jLabel14.setText("Piso");

        pisoDestinoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                pisoDestinoTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                pisoDestinoTxtKeyPressed(evt);
            }
        });

        jLabel15.setText("Departamento");

        departamentoDestinoTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                departamentoDestinoTxtFocusLost(evt);
            }
        });
        departamentoDestinoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                departamentoDestinoTxtKeyPressed(evt);
            }
        });

        jLabel16.setText("C.P.");

        codigoPostalDestinoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                codigoPostalDestinoTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                codigoPostalDestinoTxtKeyPressed(evt);
            }
        });

        jLabel17.setText("Localidad");

        localidadDestinoTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                localidadDestinoTxtFocusLost(evt);
            }
        });
        localidadDestinoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                localidadDestinoTxtKeyPressed(evt);
            }
        });

        jLabel18.setText("Provincia");

        provinciaDestinoTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                provinciaDestinoTxtFocusLost(evt);
            }
        });
        provinciaDestinoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                provinciaDestinoTxtKeyPressed(evt);
            }
        });

        jLabel19.setText("Observaciones");

        observacionesDestinoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                observacionesDestinoTxtKeyPressed(evt);
            }
        });

        jLabel26.setText("Domicilios precargados:");

        destinoComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                destinoComboBoxItemStateChanged(evt);
            }
        });
        destinoComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                destinoComboBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel19)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(observacionesDestinoTxt))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(calleDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(numeroDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(codigoPostalDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(49, 49, 49)
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(localidadDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel18)
                                .addGap(8, 8, 8)
                                .addComponent(provinciaDestinoTxt))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pisoDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(departamentoDestinoTxt))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel26)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(destinoComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel26)
                    .addComponent(destinoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(calleDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(codigoPostalDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(localidadDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(provinciaDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(observacionesDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(numeroDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(pisoDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(departamentoDestinoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        guardarViajeBtn.setText("Guardar viaje");
        guardarViajeBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarViajeBtnActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Chofer y Automovil"));

        jLabel21.setText("Chofer:");

        choferComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                choferComboBoxActionPerformed(evt);
            }
        });
        choferComboBox.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                choferComboBoxKeyPressed(evt);
            }
        });

        jLabel22.setText("Documento Chofer:");

        documentoChoferTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                documentoChoferTxtKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                documentoChoferTxtKeyPressed(evt);
            }
        });

        jLabel23.setText("Automovil");

        automovilesComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                automovilesComboBoxActionPerformed(evt);
            }
        });
        automovilesComboBox.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                automovilesComboBoxKeyPressed(evt);
            }
        });

        jLabel24.setText("Dominio");

        dominioAutomovilTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                dominioAutomovilTxtFocusLost(evt);
            }
        });
        dominioAutomovilTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                dominioAutomovilTxtKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(choferComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(documentoChoferTxt)))
                .addGap(116, 116, 116)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel23)
                    .addComponent(jLabel24))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(automovilesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dominioAutomovilTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(automovilesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel21)
                        .addComponent(choferComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel23)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(documentoChoferTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24)
                    .addComponent(dominioAutomovilTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 23, Short.MAX_VALUE))
        );

        volverBtn.setText("Volver");
        volverBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                volverBtnActionPerformed(evt);
            }
        });

        archivoMenuBtn.setText("Archivo");

        guardarViajeMenuBtn.setText("Guardar Viaje");
        guardarViajeMenuBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarViajeMenuBtnActionPerformed(evt);
            }
        });
        archivoMenuBtn.add(guardarViajeMenuBtn);

        volverMenuBtn.setText("Volver");
        volverMenuBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                volverMenuBtnActionPerformed(evt);
            }
        });
        archivoMenuBtn.add(volverMenuBtn);

        jMenuBar1.add(archivoMenuBtn);

        ayudaMenuBtn.setText("Ayuda");

        ayudaAltaPedidoMenuBtn.setText("Acerca de esta ventana");
        ayudaAltaPedidoMenuBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ayudaAltaPedidoMenuBtnActionPerformed(evt);
            }
        });
        ayudaMenuBtn.add(ayudaAltaPedidoMenuBtn);

        jMenuBar1.add(ayudaMenuBtn);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(origenPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(guardarViajeBtn)
                        .addGap(21, 21, 21)
                        .addComponent(volverBtn)))
                .addGap(21, 21, 21))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(origenPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(guardarViajeBtn)
                    .addComponent(volverBtn))
                .addGap(18, 18, 18))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void telefonoTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_telefonoTxtFocusLost
        String telefono = telefonoTxt.getText();
        Cliente cliente = llenarCamposCliente(telefono);
        if (cliente == null) {
            calleClienteTxt.requestFocus(true);
        } else {
            calleDestinoTxt.requestFocus();
        }
    }//GEN-LAST:event_telefonoTxtFocusLost

    private void calleClienteTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_calleClienteTxtKeyTyped

    }//GEN-LAST:event_calleClienteTxtKeyTyped

    private void calleClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_calleClienteTxtKeyPressed

        if (evt.getKeyCode() == 10) {
            numeroClienteTxt.requestFocus(true);
        } else {
            calleClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, java.util.Collections.EMPTY_SET);
            if (evt.getKeyCode() == KeyEvent.VK_TAB) {
                numeroClienteTxt.requestFocus(true);
            }
        }
    }//GEN-LAST:event_calleClienteTxtKeyPressed

    private void numeroClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroClienteTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            pisoClienteTxt.requestFocus(true);
        }
        numeroClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            pisoClienteTxt.requestFocus(true);
        }
    }//GEN-LAST:event_numeroClienteTxtKeyPressed

    private void departamentoClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_departamentoClienteTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            codigoPostalClienteTxt.requestFocus(true);
        }
        departamentoClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            codigoPostalClienteTxt.requestFocus(true);
        }
    }//GEN-LAST:event_departamentoClienteTxtKeyPressed

    private void codigoPostalClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_codigoPostalClienteTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            localidadClienteTxt.requestFocus(true);
        }
        codigoPostalClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            localidadClienteTxt.requestFocus(true);
        }
    }//GEN-LAST:event_codigoPostalClienteTxtKeyPressed

    private void localidadClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_localidadClienteTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            provinciaClienteTxt.requestFocus(true);
        }
        localidadClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            provinciaClienteTxt.requestFocus(true);
        }
    }//GEN-LAST:event_localidadClienteTxtKeyPressed

    private void provinciaClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_provinciaClienteTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            nombreClienteTxt.requestFocus(true);
        }
        provinciaClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            nombreClienteTxt.requestFocus(true);
        }
    }//GEN-LAST:event_provinciaClienteTxtKeyPressed

    private void apellidoClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_apellidoClienteTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            numeroDocumentoClienteTxt.requestFocus(true);
        }
        apellidoClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            numeroDocumentoClienteTxt.requestFocus(true);
        }
    }//GEN-LAST:event_apellidoClienteTxtKeyPressed

    private void nombreClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nombreClienteTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            apellidoClienteTxt.requestFocus(true);
        }
        nombreClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            apellidoClienteTxt.requestFocus(true);
        }
    }//GEN-LAST:event_nombreClienteTxtKeyPressed

    private void telefonoTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_telefonoTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            String telefono = telefonoTxt.getText();
            Cliente cliente = llenarCamposCliente(telefono);
            if (cliente == null) {
                calleClienteTxt.requestFocus(true);
            } else {
                calleDestinoTxt.requestFocus();
            }
        }
        calleClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            String telefono = telefonoTxt.getText();
            Cliente cliente = llenarCamposCliente(telefono);
            if (cliente == null) {
                calleClienteTxt.requestFocus(true);
            } else {
                calleDestinoTxt.requestFocus();
            }
        }
    }//GEN-LAST:event_telefonoTxtKeyPressed

    private void pisoClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pisoClienteTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            departamentoClienteTxt.requestFocus(true);
        }
        pisoClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            departamentoClienteTxt.requestFocus(true);
        }

    }//GEN-LAST:event_pisoClienteTxtKeyPressed

    private void numeroDocumentoClienteTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroDocumentoClienteTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            calleDestinoTxt.requestFocus(true);
        }
        numeroDocumentoClienteTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            calleDestinoTxt.requestFocus(true);
        }
    }//GEN-LAST:event_numeroDocumentoClienteTxtKeyPressed

    private void calleDestinoTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_calleDestinoTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            numeroDestinoTxt.requestFocus(true);
        }
        calleDestinoTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            numeroDestinoTxt.requestFocus(true);
        }
    }//GEN-LAST:event_calleDestinoTxtKeyPressed

    private void numeroDestinoTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroDestinoTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            pisoDestinoTxt.requestFocus(true);
        }
        numeroDestinoTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            pisoDestinoTxt.requestFocus(true);
        }
    }//GEN-LAST:event_numeroDestinoTxtKeyPressed

    private void pisoDestinoTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pisoDestinoTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            departamentoDestinoTxt.requestFocus(true);
        }
        pisoDestinoTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            departamentoDestinoTxt.requestFocus(true);
        }
    }//GEN-LAST:event_pisoDestinoTxtKeyPressed

    private void departamentoDestinoTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_departamentoDestinoTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            codigoPostalDestinoTxt.requestFocus(true);
        }
        departamentoDestinoTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            codigoPostalDestinoTxt.requestFocus(true);
        }
    }//GEN-LAST:event_departamentoDestinoTxtKeyPressed

    private void codigoPostalDestinoTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_codigoPostalDestinoTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            localidadDestinoTxt.requestFocus(true);
        }
        codigoPostalDestinoTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            localidadDestinoTxt.requestFocus(true);
        }
    }//GEN-LAST:event_codigoPostalDestinoTxtKeyPressed

    private void localidadDestinoTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_localidadDestinoTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            provinciaDestinoTxt.requestFocus(true);
        }
        localidadDestinoTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            provinciaDestinoTxt.requestFocus(true);
        }
    }//GEN-LAST:event_localidadDestinoTxtKeyPressed

    private void provinciaDestinoTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_provinciaDestinoTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            observacionesDestinoTxt.requestFocus(true);
        }
        provinciaDestinoTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            observacionesDestinoTxt.requestFocus(true);
        }
    }//GEN-LAST:event_provinciaDestinoTxtKeyPressed

    private void observacionesDestinoTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_observacionesDestinoTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            choferComboBox.requestFocus(true);
        }
        observacionesDestinoTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            choferComboBox.requestFocus(true);
        }
    }//GEN-LAST:event_observacionesDestinoTxtKeyPressed

    private void choferComboBoxKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_choferComboBoxKeyPressed
        if (evt.getKeyCode() == 10) {
            documentoChoferTxt.requestFocus(true);
        }
        choferComboBox.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            documentoChoferTxt.requestFocus(true);
        }
    }//GEN-LAST:event_choferComboBoxKeyPressed

    private void documentoChoferTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_documentoChoferTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            automovilesComboBox.requestFocus(true);
        }
        documentoChoferTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            automovilesComboBox.requestFocus(true);
        }
    }//GEN-LAST:event_documentoChoferTxtKeyPressed

    private void automovilesComboBoxKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_automovilesComboBoxKeyPressed
        if (evt.getKeyCode() == 10) {
            dominioAutomovilTxt.requestFocus(true);
        }
        automovilesComboBox.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            dominioAutomovilTxt.requestFocus(true);
        }
    }//GEN-LAST:event_automovilesComboBoxKeyPressed

    private void dominioAutomovilTxtKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dominioAutomovilTxtKeyPressed
        if (evt.getKeyCode() == 10) {
            guardarViajeBtn.requestFocus(true);
        }
        dominioAutomovilTxt.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                java.util.Collections.EMPTY_SET);
        if (evt.getKeyCode() == KeyEvent.VK_TAB) {
            guardarViajeBtn.requestFocus(true);
        }
    }//GEN-LAST:event_dominioAutomovilTxtKeyPressed

    private void telefonoTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_telefonoTxtKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            evt.consume();            // Si la tecla ingresada no es un numero, se ignora la misma.
        }
    }//GEN-LAST:event_telefonoTxtKeyTyped

    private void numeroClienteTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroClienteTxtKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            evt.consume();            // Si la tecla ingresada no es un numero, se ignora la misma.
        }
    }//GEN-LAST:event_numeroClienteTxtKeyTyped

    private void pisoClienteTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pisoClienteTxtKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            evt.consume();            // Si la tecla ingresada no es un numero, se ignora la misma.
        }
    }//GEN-LAST:event_pisoClienteTxtKeyTyped

    private void codigoPostalClienteTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_codigoPostalClienteTxtKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            evt.consume();            // Si la tecla ingresada no es un numero, se ignora la misma.
        }
    }//GEN-LAST:event_codigoPostalClienteTxtKeyTyped

    private void numeroDocumentoClienteTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroDocumentoClienteTxtKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            evt.consume();            // Si la tecla ingresada no es un numero, se ignora la misma.
        }
    }//GEN-LAST:event_numeroDocumentoClienteTxtKeyTyped

    private void numeroDestinoTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroDestinoTxtKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            evt.consume();            // Si la tecla ingresada no es un numero, se ignora la misma.
        }
    }//GEN-LAST:event_numeroDestinoTxtKeyTyped

    private void pisoDestinoTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pisoDestinoTxtKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            evt.consume();            // Si la tecla ingresada no es un numero, se ignora la misma.
        }
    }//GEN-LAST:event_pisoDestinoTxtKeyTyped

    private void codigoPostalDestinoTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_codigoPostalDestinoTxtKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            evt.consume();            // Si la tecla ingresada no es un numero, se ignora la misma.
        }
    }//GEN-LAST:event_codigoPostalDestinoTxtKeyTyped

    private void documentoChoferTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_documentoChoferTxtKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            evt.consume();            // Si la tecla ingresada no es un numero, se ignora la misma.
        }
    }//GEN-LAST:event_documentoChoferTxtKeyTyped

    private void calleClienteTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_calleClienteTxtFocusLost
        String calle = calleClienteTxt.getText();
        if (calle != null) {
            calleClienteTxt.setText(calle.toUpperCase());
        }
    }//GEN-LAST:event_calleClienteTxtFocusLost

    private void departamentoClienteTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_departamentoClienteTxtFocusLost
        String departamentoCliente = departamentoClienteTxt.getText();
        if (departamentoCliente != null) {
            departamentoClienteTxt.setText(departamentoCliente.toUpperCase());
        }
    }//GEN-LAST:event_departamentoClienteTxtFocusLost

    private void localidadClienteTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_localidadClienteTxtFocusLost
        String localidadCliente = localidadClienteTxt.getText();
        if (localidadCliente != null) {
            localidadClienteTxt.setText(localidadCliente.toUpperCase());
        }
    }//GEN-LAST:event_localidadClienteTxtFocusLost

    private void provinciaClienteTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_provinciaClienteTxtFocusLost
        String provinciaCliente = provinciaClienteTxt.getText();
        if (provinciaCliente != null) {
            provinciaClienteTxt.setText(provinciaCliente.toUpperCase());
        }
    }//GEN-LAST:event_provinciaClienteTxtFocusLost

    private void nombreClienteTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nombreClienteTxtFocusLost
        String nombreCliente = nombreClienteTxt.getText();
        if (nombreCliente != null) {
            nombreClienteTxt.setText(nombreCliente.toUpperCase());
        }
    }//GEN-LAST:event_nombreClienteTxtFocusLost

    private void apellidoClienteTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_apellidoClienteTxtFocusLost
        String apellidoCliente = apellidoClienteTxt.getText();
        if (apellidoCliente != null) {
            apellidoClienteTxt.setText(apellidoCliente.toUpperCase());
        }
    }//GEN-LAST:event_apellidoClienteTxtFocusLost

    private void calleDestinoTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_calleDestinoTxtFocusLost
        String calle = calleDestinoTxt.getText();
        if (calle != null) {
            calleDestinoTxt.setText(calle.toUpperCase());
        }
    }//GEN-LAST:event_calleDestinoTxtFocusLost

    private void departamentoDestinoTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_departamentoDestinoTxtFocusLost
        String departamento = departamentoDestinoTxt.getText();
        if (departamento != null) {
            departamentoDestinoTxt.setText(departamento.toUpperCase());
        }
    }//GEN-LAST:event_departamentoDestinoTxtFocusLost

    private void localidadDestinoTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_localidadDestinoTxtFocusLost
        String localidad = localidadDestinoTxt.getText();
        if (localidad != null) {
            localidadDestinoTxt.setText(localidad.toUpperCase());
        }
    }//GEN-LAST:event_localidadDestinoTxtFocusLost

    private void provinciaDestinoTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_provinciaDestinoTxtFocusLost
        String provincia = provinciaDestinoTxt.getText();
        if (provincia != null) {
            provinciaDestinoTxt.setText(provincia.toUpperCase());
        }
    }//GEN-LAST:event_provinciaDestinoTxtFocusLost

    private void dominioAutomovilTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_dominioAutomovilTxtFocusLost
        String dominio = dominioAutomovilTxt.getText();
        if (dominio != null) {
            dominioAutomovilTxt.setText(dominio.toUpperCase());
        }
    }//GEN-LAST:event_dominioAutomovilTxtFocusLost

    private void guardarViajeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarViajeBtnActionPerformed
        String mensaje = this.validarCampos();
        if (mensaje != null) {
            JOptionPane.showMessageDialog(this, mensaje);
        } else {
            this.guardarViaje();
        }
    }//GEN-LAST:event_guardarViajeBtnActionPerformed

    private void choferComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choferComboBoxActionPerformed
        this.mostrarInfoChofer();
    }//GEN-LAST:event_choferComboBoxActionPerformed

    private void automovilesComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_automovilesComboBoxActionPerformed
        this.mostrarInfoAuto();
    }//GEN-LAST:event_automovilesComboBoxActionPerformed

    private void volverBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_volverBtnActionPerformed
        this.irAMenuPrincipal();
    }//GEN-LAST:event_volverBtnActionPerformed

    private void origenComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_origenComboBoxItemStateChanged

    }//GEN-LAST:event_origenComboBoxItemStateChanged

    private void destinoComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_destinoComboBoxItemStateChanged

    }//GEN-LAST:event_destinoComboBoxItemStateChanged

    private void guardarClienteBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarClienteBtnActionPerformed
        this.guardarCliente();
    }//GEN-LAST:event_guardarClienteBtnActionPerformed

    private void guardarViajeMenuBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarViajeMenuBtnActionPerformed
        String mensaje = this.validarCampos();
        if (mensaje != null) {
            JOptionPane.showMessageDialog(this, mensaje);
        } else {
            this.guardarViaje();
        }
    }//GEN-LAST:event_guardarViajeMenuBtnActionPerformed

    private void volverMenuBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_volverMenuBtnActionPerformed
        this.irAMenuPrincipal();
    }//GEN-LAST:event_volverMenuBtnActionPerformed

    private void ayudaAltaPedidoMenuBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ayudaAltaPedidoMenuBtnActionPerformed
        this.mostrarAyudaAltaPedido();
    }//GEN-LAST:event_ayudaAltaPedidoMenuBtnActionPerformed

    private void origenComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_origenComboBoxActionPerformed
        try {
            this.llenarCamposClienteByDestinoFrecuente();
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex);
        }
    }//GEN-LAST:event_origenComboBoxActionPerformed

    private void destinoComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_destinoComboBoxActionPerformed
        try {
            this.llenarCamposDestinoByDestinoFrecuente();
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex);
        }
    }//GEN-LAST:event_destinoComboBoxActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AltaPedidoFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AltaPedidoFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AltaPedidoFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AltaPedidoFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AltaPedidoFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField apellidoClienteTxt;
    private javax.swing.JMenu archivoMenuBtn;
    private javax.swing.JComboBox automovilesComboBox;
    private javax.swing.JMenuItem ayudaAltaPedidoMenuBtn;
    private javax.swing.JMenu ayudaMenuBtn;
    private javax.swing.JTextField calleClienteTxt;
    private javax.swing.JTextField calleDestinoTxt;
    private javax.swing.JComboBox choferComboBox;
    private javax.swing.JTextField codigoPostalClienteTxt;
    private javax.swing.JTextField codigoPostalDestinoTxt;
    private javax.swing.JTextField departamentoClienteTxt;
    private javax.swing.JTextField departamentoDestinoTxt;
    private javax.swing.JComboBox destinoComboBox;
    private javax.swing.JTextField documentoChoferTxt;
    private javax.swing.JTextField dominioAutomovilTxt;
    private com.toedter.calendar.JDateChooser fechaRecogidaChooser;
    private javax.swing.JButton guardarClienteBtn;
    private javax.swing.JButton guardarViajeBtn;
    private javax.swing.JMenuItem guardarViajeMenuBtn;
    private javax.swing.JFormattedTextField horarioRecogidaTxt;
    private javax.swing.JLabel informacionLbl;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField localidadClienteTxt;
    private javax.swing.JTextField localidadDestinoTxt;
    private javax.swing.JTextField nombreClienteTxt;
    private javax.swing.JTextField numeroClienteTxt;
    private javax.swing.JTextField numeroDestinoTxt;
    private javax.swing.JTextField numeroDocumentoClienteTxt;
    private javax.swing.JTextField observacionesDestinoTxt;
    private javax.swing.JComboBox origenComboBox;
    private javax.swing.JPanel origenPanel;
    private javax.swing.JTextField pisoClienteTxt;
    private javax.swing.JTextField pisoDestinoTxt;
    private javax.swing.JTextField provinciaClienteTxt;
    private javax.swing.JTextField provinciaDestinoTxt;
    private javax.swing.JTextField telefonoTxt;
    private javax.swing.JComboBox tipoDocumentoComboBox;
    private javax.swing.JButton volverBtn;
    private javax.swing.JMenuItem volverMenuBtn;
    // End of variables declaration//GEN-END:variables

    private Cliente llenarCamposCliente(String telefono) {

        ClienteBO clienteBO = new ClienteBO();
        Cliente cliente = new Cliente();

        try {
            cliente = clienteBO.getClienteByTelefono(telefono);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage() + "\nDebera cargar los datos manualmente.");
            cliente = null;
        }

        if (cliente != null) {
            // Asigno el cliente obtenido al clienteActual. Si este no se modifica, se utiliza su domicilio para el viaje.
            clienteActual = cliente;
            guardarClienteBtn.setVisible(false);
            // Llenar campos.
            informacionLbl.setText("Cliente ya existente.");
            nombreClienteTxt.setText(cliente.getNombre());
            apellidoClienteTxt.setText(cliente.getApellido());
            calleClienteTxt.setText(cliente.getDomicilio().getCalle());
            numeroClienteTxt.setText(String.valueOf(cliente.getDomicilio().getNumero()));
            pisoClienteTxt.setText(String.valueOf(cliente.getDomicilio().getPiso()));
            departamentoClienteTxt.setText(cliente.getDomicilio().getDepartamento());
            codigoPostalClienteTxt.setText(String.valueOf(cliente.getDomicilio().getCodigoPostal()));
            localidadClienteTxt.setText(cliente.getDomicilio().getLocalidad());
            provinciaClienteTxt.setText(cliente.getDomicilio().getProvincia());
//            documentoClienteTxt.setText(String.valueOf(cliente.getDocumento().getNumero()));
            numeroDocumentoClienteTxt.setText(cliente.getDocumento().getTipoDeDocumento().getDescripcion()
                    + " - " + cliente.getDocumento().getNumero());
            
            guardarViajeBtn.setEnabled(true);
        } else {
            guardarClienteBtn.setVisible(true);
            guardarViajeBtn.setEnabled(false);
        }

        return cliente;
    }

    private String validarCampos() {

        if (calleClienteTxt.getText().equals("") || calleClienteTxt.getText().length() == 0) {
            return "Debe completar calle de origen.";
        }

        if (nombreClienteTxt.getText().equals("") || nombreClienteTxt.getText().length() == 0) {
            return "Debe completar nombre del cliente.";
        }

        if (apellidoClienteTxt.getText().equals("") || apellidoClienteTxt.getText().length() == 0) {
            return "Debe completar apellido del cliente.";
        }

        if (calleDestinoTxt.getText().equals("") || calleDestinoTxt.getText().length() == 0) {
            return "Debe completar calle de destino.";
        }

        return null;
    }

    private void guardarViaje() {
        // Armo domicilio de origen y cliente
        Domicilio domicilioOrigen = new Domicilio();
        domicilioOrigen = this.armarDomicilioCliente();

//        if(clienteActual == null){
//        
//            
//            clienteActual = new Cliente();
//            clienteActual.setDomicilio(domicilioOrigen);
//            clienteActual.setNombre(nombreClienteTxt.getText());
//            clienteActual.setApellido(apellidoClienteTxt.getText());
//            Documento documento = new Documento();
//            int index = tipoDocumentoComboBox.getSelectedIndex();
//            if(index != -1){
//                documento.setTipoDeDocumento(tiposDocumentoList.get(index));
//            }
//            documento.setNumero(Long.valueOf(numeroDocumentoClienteTxt.getText()));
//            clienteActual.setDocumento(documento);
//            clienteActual.setTelefono(telefonoTxt.getText());
//        }
        // Armo domicilio de destino:
        Domicilio domicilioDestino = new Domicilio();
        domicilioDestino = this.armarDomicilioDestino();

        // Le doy formato a la hora de recogida.
        String horarioRecogida = horarioRecogidaTxt.getText(); // Obtengo la hora en un formato hh:mm PM/AM (Segun el jFormattedText)
        Calendar fechaRecogida = fechaRecogidaChooser.getCalendar(); // Obtengo la fecha ingresada por el calendario
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm aa");
        Date date = new Date();
        if(horarioRecogida.equals("") || fechaRecogida == null){
            fechaRecogida = Calendar.getInstance();
        }else{
            try {
                date = sdf.parse(horarioRecogida); // Le asigno a date el valor del horario ingresado
                int horas = date.getHours(); // Obtengo las horas
                int minutos = date.getMinutes(); // Obtengo los minutos
                fechaRecogida.set(Calendar.HOUR_OF_DAY, horas); // A la fecha elegida en el calendario, le agrego la hora y los minutos
                fechaRecogida.set(Calendar.MINUTE, minutos);
            } catch (ParseException ex) {
                Logger.getLogger(AltaPedidoFrame.class.getName()).log(Level.SEVERE, null, ex);
                fechaRecogida = Calendar.getInstance();
            }
        }
        // Obtengo chofer:
        int index = choferComboBox.getSelectedIndex();
        Chofer choferAsignado = listaChoferes.get(index);
        index = automovilesComboBox.getSelectedIndex();
        Auto autoAsignado = listaAutos.get(index);
        try{
            ViajeBO viajeBO = new ViajeBO();
            viajeBO.saveNewViaje(clienteActual, domicilioOrigen, domicilioDestino, fechaRecogida, choferAsignado, autoAsignado);
            JOptionPane.showMessageDialog(this, PropertiesReader.getInstance().getApplicationMessage("info.alta.pedido.guardadook"));
        }catch(Exception ex){
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex);
        }

    }

    private void getChoferes() {
        List<Chofer> choferesList = new ArrayList<Chofer>();
        ChoferBO choferBO = new ChoferBO();
        try {
            choferesList = choferBO.getAllChoferes();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex);
        }

        if (choferesList != null && !choferesList.isEmpty()) {
            for (Chofer chofer : choferesList) {
                choferComboBox.addItem(chofer.getApellido() + " " + chofer.getNombre());
                listaChoferes.add(chofer);
            }
        }
    }

    private void getAutomoviles() {
        List<Auto> autosList = new ArrayList<Auto>();
        AutoBO autoBO = new AutoBO();
        try {
            autosList = autoBO.getAllAutos();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex);
        }

        if (autosList != null && !autosList.isEmpty()) {
            for (Auto auto : autosList) {
                automovilesComboBox.addItem("" + auto.getCodigo() + " - " + auto.getMarca() + " - " + auto.getColor());
                listaAutos.add(auto);
            }
        }
    }

    private void mostrarInfoChofer() {

        int index = choferComboBox.getSelectedIndex();

        if (index != -1 && listaChoferes != null && !listaChoferes.isEmpty()) {
            Long documentoChofer = listaChoferes.get(index).getDocumento().getNumero();
            documentoChoferTxt.setText(String.valueOf(documentoChofer));
        }

    }

    private void mostrarInfoAuto() {
        int index = automovilesComboBox.getSelectedIndex();
        if (index != -1 && listaAutos != null && !listaAutos.isEmpty()) {
            String dominioAuto = listaAutos.get(index).getPatente();
            dominioAutomovilTxt.setText(dominioAuto);
        }
    }

    private void getTiposDocumento() {
        List<TipoDeDocumento> tiposDocList = new ArrayList<TipoDeDocumento>();
        TipoDeDocumentoBO tipoDeDocumentoBO = new TipoDeDocumentoBO();
        try {
            tiposDocList = tipoDeDocumentoBO.getAllTipoDeDocumento();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex);
        }

        if (tiposDocList != null && !tiposDocList.isEmpty()) {
            for (TipoDeDocumento tdd : tiposDocList) {
                tipoDocumentoComboBox.addItem(tdd.getDescripcion());
                tiposDocumentoList.add(tdd);
            }
        }
    }

    private void irAMenuPrincipal() {
        MenuPrincipalFrame mpf = new MenuPrincipalFrame();
        mpf.setVisible(true);
        this.dispose();
    }

    private void getDomiciliosPrecargados() {
        DestinoFrecuenteBO destinoFrecuenteBO = new DestinoFrecuenteBO();
        List<DestinoFrecuente> destinos = new ArrayList<DestinoFrecuente>();
        try {
            destinos = destinoFrecuenteBO.getAllDestinos();
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex);
        }
        if (destinos != null && !destinos.isEmpty()) {
            DefaultComboBoxModel modelo1 = (DefaultComboBoxModel) origenComboBox.getModel();
            DefaultComboBoxModel modelo2 = (DefaultComboBoxModel) destinoComboBox.getModel();
            for (DestinoFrecuente df : destinos) {
                modelo1.addElement(df.getNombre());
                modelo2.addElement(df.getNombre());
                destinosFrecuentesList.add(df);
            }
            origenComboBox.setModel(modelo1);
            destinoComboBox.setModel(modelo2);
        }
    }

    private void llenarCamposClienteByDestinoFrecuente() throws Exception {
        int index = origenComboBox.getSelectedIndex();
        if (index < 0) {
            throw new Exception("Error en la seleccion de domicilio precargado");
        } else {
            if (destinosFrecuentesList.size() > 0) {
                Domicilio domOrig = destinosFrecuentesList.get(index).getDomicilio();
                calleClienteTxt.setText(domOrig.getCalle());
                if (domOrig.getNumero() != null) {
                    numeroClienteTxt.setText(String.valueOf(domOrig.getNumero()));
                } else {
                    numeroClienteTxt.setText("");
                }

                if (domOrig.getPiso() != null) {
                    pisoClienteTxt.setText(String.valueOf(domOrig.getPiso()));
                } else {
                    pisoClienteTxt.setText("");
                }
                departamentoClienteTxt.setText(domOrig.getDepartamento());
                if (domOrig.getCodigoPostal() != null) {
                    codigoPostalClienteTxt.setText(String.valueOf(domOrig.getCodigoPostal()));
                } else {
                    codigoPostalClienteTxt.setText("");
                }
                localidadClienteTxt.setText(domOrig.getLocalidad());
                provinciaClienteTxt.setText(domOrig.getProvincia());
            }
        }
    }

    private void llenarCamposDestinoByDestinoFrecuente() throws Exception {

        int index = destinoComboBox.getSelectedIndex();
        if (index < 0) {
            throw new Exception("Error en la seleccion de domicilio precargado");
        } else {
            if (destinosFrecuentesList.size() > 0) {
                Domicilio domDestino = destinosFrecuentesList.get(index).getDomicilio();
                calleDestinoTxt.setText(domDestino.getCalle());
                if (domDestino.getNumero() != null) {
                    numeroDestinoTxt.setText(String.valueOf(domDestino.getNumero()));
                } else {
                    numeroDestinoTxt.setText("");
                }

                if (domDestino.getPiso() != null) {
                    pisoDestinoTxt.setText(String.valueOf(domDestino.getPiso()));
                } else {
                    pisoDestinoTxt.setText("");
                }
                departamentoDestinoTxt.setText(domDestino.getDepartamento());
                if (domDestino.getCodigoPostal() != null) {
                    codigoPostalDestinoTxt.setText(String.valueOf(domDestino.getCodigoPostal()));
                } else {
                    codigoPostalDestinoTxt.setText("");
                }
                localidadDestinoTxt.setText(domDestino.getLocalidad());
                provinciaDestinoTxt.setText(domDestino.getProvincia());
            }
        }
    }

    private Domicilio armarDomicilioCliente() {
        Domicilio domicilio = new Domicilio();

        domicilio.setCalle(calleClienteTxt.getText());
        domicilio.setNumero(Integer.valueOf(numeroClienteTxt.getText()));
        if (pisoClienteTxt.getText() != "" && pisoClienteTxt.getText().length() > 0) {
            domicilio.setPiso(Integer.valueOf(pisoClienteTxt.getText()));
        }
        domicilio.setDepartamento(departamentoClienteTxt.getText());
        domicilio.setCodigoPostal(Integer.valueOf(codigoPostalClienteTxt.getText()));
        domicilio.setLocalidad(localidadClienteTxt.getText());
        domicilio.setProvincia(provinciaClienteTxt.getText());
        return domicilio;
    }

    private Domicilio armarDomicilioDestino() {
        Domicilio domicilio = new Domicilio();
        domicilio.setCalle(calleDestinoTxt.getText());
        domicilio.setNumero(Integer.valueOf(numeroDestinoTxt.getText()));
        if (pisoDestinoTxt.getText() != "" && pisoDestinoTxt.getText().length() > 0) {
            domicilio.setPiso(Integer.valueOf(pisoDestinoTxt.getText()));
        }
        domicilio.setDepartamento(departamentoDestinoTxt.getText());
        domicilio.setCodigoPostal(Integer.valueOf(codigoPostalDestinoTxt.getText()));
        domicilio.setLocalidad(localidadDestinoTxt.getText());
        domicilio.setProvincia(provinciaDestinoTxt.getText());

        return domicilio;
    }

    private void guardarCliente() {
        Domicilio domicilioCliente = this.armarDomicilioCliente();
        clienteActual = new Cliente();
        clienteActual.setNombre(nombreClienteTxt.getText());
        clienteActual.setApellido(apellidoClienteTxt.getText());
        clienteActual.setDomicilio(domicilioCliente);
        clienteActual.setTelefono(telefonoTxt.getText());

        clienteActual.setDocumento(new Documento());
        int index = tipoDocumentoComboBox.getSelectedIndex();
        if (index > -1) {
            clienteActual.getDocumento().setTipoDeDocumento(tiposDocumentoList.get(index));
            clienteActual.getDocumento().setNumero(Long.valueOf(numeroDocumentoClienteTxt.getText()));
        }

        ClienteBO clienteBO = new ClienteBO();
        try {
            clienteBO.saveNewCliente(clienteActual);
            guardarViajeBtn.setEnabled(true);
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex);
        }
    }

    private void mostrarAyudaAltaPedido() {

        String mensaje = PropertiesReader.getInstance().getApplicationMessage("ayuda.acerca.altaPedido");
        JOptionPane.showMessageDialog(this, mensaje);

    }

}
